package com.SpringBo.login.service;



import com.SpringBo.login.entity.Account;
import com.SpringBo.login.mapper.AccountMapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.util.*;

@Service
public class LoginService {
    private ObjectMapper om = new ObjectMapper();
    @Resource
    private AccountMapper accountMapper;

    /**
     * 添加方法
     */
    public String addAccount(Account account) throws Exception{
        Map<String,Object> result = new HashMap<>();
        System.out.println("用户名-----"+account.getUsername()+",密码----------"+account.getPassword());
        account.setAccountId(UUID.randomUUID().toString().replaceAll("-",""));
        account.setCreateBy("System");
        account.setCreateTime(new Date());
        accountMapper.insert(account);
        result.put("username",account.getUsername());
        return om.writeValueAsString(result);
    }


    /**
     * 测试
     */
    public String testing(String value) throws Exception {
        Map<String,Object> result = new HashMap<String,Object>();
        if(StringUtils.isNotBlank(value)){
           result.put("error",false);
           result.put("user",value);
        }else{
            result.put("error",true);
            result.put("reason","没找到");
        }
        return om.writeValueAsString(result);
    }
}
